package com.kantboot.functional.pay.wechat.controller;

import com.kantboot.functional.pay.wechat.service.IFunctionalPayWechatOrderService;
import com.kantboot.functional.pay.wechat.util.WechatPayResult;
import com.kantboot.util.common.result.RestResult;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 关于微信支付的服务
 */
@RestController
@RequestMapping("/functional-pay-wechat/order")
public class FunctionalPayWechatOrderController {

    @Resource
    private IFunctionalPayWechatOrderService service;

    /**
     * 获取支付结果
     */
    @RequestMapping("/getPayResultByMp")
    public RestResult<WechatPayResult> getPayResultByMp(
            @RequestParam("orderId") Long orderId,
            @RequestParam("code") String code) {
        return RestResult.success(service.getPayResultByMp(orderId, code),"getSuccess","获取成功");
    }


    /**
     * 处理微信支付回调
     * @param order 路径参数
     */
    @RequestMapping("/handleWechatPayCallback/{order}")
    public RestResult handleWechatPayCallback(@PathVariable("order") String order) {
        return RestResult.success(service.handleWechatPay(order), "handleSuccess", "处理成功");
    }

    /**
     * 由前端调用处理微信支付
     */
    @RequestMapping("/handleWechatPay")
    public RestResult handleWechatPay(@RequestParam("orderId") Long orderId) {
        return RestResult.success(service.handleWechatPay(orderId+""), "handleSuccess", "处理成功");
    }

    /**
     * 整单退款
     */
    @RequestMapping("/refundByOrder")
    public RestResult refundByOrder(@RequestParam("orderId") Long orderId) {
        return RestResult.success(service.refundByOrder(orderId+""), "refundSuccess", "退款成功");
    }

}
